package com.youyi.yyscreencutlibrary.ColoPicker;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Shader;
import android.support.v4.internal.view.SupportMenu;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK;

public class ZoomBitmapView extends View {
    private static final int FACTOR = 2;
    private static final int RADIUS = 100;
    private int centerX;
    private int centerY;
    private int lineColor = -65536;
    private int lineLength = 20;
    private Bitmap mBbitmap;
    private Paint mLinePaint;
    private OnResultListener mOnResultListener;
    private int mScreenHeight;
    private int mScreenWidth;
    private Paint paint;

    public interface OnResultListener {
        void result(int i, int i2, String str);
    }

    public void setOnResultListener(OnResultListener onResultListener) {
        this.mOnResultListener = onResultListener;
    }

    public ZoomBitmapView(Context context) {
        super(context);
    }

    public ZoomBitmapView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        Paint paint2 = new Paint();
        this.mLinePaint = paint2;
        paint2.setColor(this.lineColor);
        this.mLinePaint.setStyle(Paint.Style.STROKE);
        this.mLinePaint.setStrokeWidth(2.0f);
        this.mLinePaint.setAntiAlias(true);
        this.mScreenWidth = context.getResources().getDisplayMetrics().widthPixels;
        this.mScreenHeight = context.getResources().getDisplayMetrics().heightPixels;
    }

    public void setBitmap(Bitmap bitmap) {
        this.mBbitmap = bitmap;
        BitmapShader bitmapShader = new BitmapShader(Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() * 2, this.mBbitmap.getHeight() * 2, true), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        Paint paint2 = new Paint(1);
        this.paint = paint2;
        paint2.setShader(bitmapShader);
        this.centerY = 100;
        this.centerX = 100;
        int i = this.mScreenWidth / 2;
        int i2 = this.mScreenHeight / 2;
        Matrix matrix = new Matrix();
        matrix.setTranslate((float) ((-i) * 1), (float) ((-i2) * 1));
        this.paint.getShader().setLocalMatrix(matrix);
        this.centerX = i;
        this.centerY = i2;
        if (this.mOnResultListener != null) {
            String colorByXY = YYScreenCutSDK.getColorByXY(this.mBbitmap, i, i2, false);
            if (colorByXY.equals("FF0000")) {
                this.mLinePaint.setColor(-1);
            } else {
                this.mLinePaint.setColor(this.lineColor);
            }
            OnResultListener onResultListener = this.mOnResultListener;
            if (onResultListener != null) {
                onResultListener.result(this.centerX, this.centerY, colorByXY);
            }
        }
        invalidate();
    }

    /* access modifiers changed from: protected */
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Bitmap bitmap = this.mBbitmap;
        if (bitmap != null) {
            canvas.drawBitmap(bitmap, 0.0f, 0.0f, this.paint);
            canvas.drawCircle((float) this.centerX, (float) this.centerY, 100.0f, this.paint);
            canvas.drawCircle((float) this.centerX, (float) this.centerY, 100.0f, this.mLinePaint);
            int i = this.centerX;
            int i2 = this.lineLength;
            int i3 = this.centerY;
            canvas.drawLine((float) (i - i2), (float) i3, (float) (i + i2), (float) i3, this.mLinePaint);
            int i4 = this.centerX;
            int i5 = this.centerY;
            int i6 = this.lineLength;
            canvas.drawLine((float) i4, (float) (i5 - i6), (float) i4, (float) (i5 + i6), this.mLinePaint);
        }
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (this.mBbitmap != null) {
            int x = (int) motionEvent.getX();
            int y = (int) motionEvent.getY();
            Matrix matrix = new Matrix();
            matrix.setTranslate((float) ((-x) * 1), (float) ((-y) * 1));
            this.paint.getShader().setLocalMatrix(matrix);
            this.centerX = x;
            this.centerY = y;
            if (this.mOnResultListener != null) {
                String colorByXY = YYScreenCutSDK.getColorByXY(this.mBbitmap, x, y, false);
                if (colorByXY.equals("FF0000")) {
                    this.mLinePaint.setColor(-1);
                } else {
                    this.mLinePaint.setColor(this.lineColor);
                }
                OnResultListener onResultListener = this.mOnResultListener;
                if (onResultListener != null) {
                    onResultListener.result(this.centerX, this.centerY, colorByXY);
                }
            }
            invalidate();
        }
        return true;
    }
}
